import 'package:flutter/material.dart';
import 'package:flutter_syt/domain/widgets/simple_image_loader.dart';

class NewsCoverEntity {
  late bool isHot;
  late String title;
  late String linkUrl;
  late String coverUrl;
  String? color;
  NewsCoverEntity();

  factory NewsCoverEntity.create(
    bool isHot,
    String title,
    String linkUrl,
    String coverUrl,
    String? colorStr,
  ) {
    return NewsCoverEntity()
      ..isHot = isHot
      ..title = title
      ..linkUrl = linkUrl
      ..color = '0xFF$colorStr'
      ..coverUrl = coverUrl;
  }
}

class NewsCover extends StatefulWidget {
  final NewsCoverEntity entity;

  NewsCover(this.entity, {Key? key});

  @override
  State<StatefulWidget> createState() => NewsCoverState();
}

class NewsCoverState extends State<NewsCover> {
  @override
  Widget build(BuildContext context) {
    var imgWidth = MediaQuery.of(context).size.width - 32;
    return Container(
      width: imgWidth,
      height: 108,
      child: ClipRRect(
        borderRadius: BorderRadius.circular(12),
        child: ImageLoader.loadImage(
          imageUrl: widget.entity.coverUrl,
          width: imgWidth,
          height: 108,
        ),
      ),
    );
  }
}
